var express = require('express');
var router = express.Router();

let userServices = require("../src/services/userServices")

//用户的登录
router.get('/login/:username/:pwd', async function(req, res, next) {
  let {username,pwd} = req.params
  let result = await userServices.login(username,pwd);
  if(result){
    res.json({code:0,msg:"登录成功"})
  }else{
    res.json({code:1,msg:"用户名或者密码错误"})
  }
});
//用户的添加
router.post('/adduser', async function(req, res, next) {
  let {username,pwd} = req.body
  let result = await userServices.addUser(username,pwd);
  if(result){
    res.json({code:0,msg:"添加成功"})
  }else{
    res.json({code:1,msg:"用户名重复"})
  }
});


module.exports = router;
